import axios from 'axios';
import query from 'query-string';

const BASE_URL = '/product/attribute/value';


export interface AttributeValueParam {
    keyId?: number;
    page?: number;
    size?: number;
    sort?: Array<string>;
}

export interface AttributeValueResponse {
    id?: number;
    keyId?: number;
    value?: string;
    
    createdBy?: string;
    updatedBy?: string;
    createdAt?: string;
    updatedAt?: string;
}

export interface AttributeValueSaveCommand {
    id?: number;
    keyId?: number;
    value?: string;
}

export interface AttributeValueResponseList {
    list: AttributeValueResponse[];
    total: number;
}


// 通过AttributeValueParam参数获取分页列表
export function pageAttributeValue(params: AttributeValueParam) {
    return axios.get<AttributeValueResponseList>(`${BASE_URL}/page`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    })
}

// 通过id获取attributeValue信息
export function getAttributeValue(id: number) {
    return axios.get<AttributeValueResponse>(`${BASE_URL}/${id}`);
    
}

export function listAttributeValue(params: AttributeValueParam) {
    return axios.get<AttributeValueResponse[]>(`${BASE_URL}/list`, {
        params, paramsSerializer: (obj) => {
            return query.stringify(obj);
        }
    });
}

// 添加attributeValue
export function addAttributeValue(params: AttributeValueSaveCommand) {
    return axios.post(`${BASE_URL}/add`, params);
}

// 更新attributeValue
export function updateAttributeValue(params: AttributeValueSaveCommand) {
    return axios.put(`${BASE_URL}/update`, params);
}

// 批量删除attributeValue
export function deleteAttributeValue(ids: number | Array<number>) {
    return axios.delete(`${BASE_URL}/${ids}`);
}